package com.by.controller;

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LittleDesire
 * @description
 * @date 2022-03-25 周五 9:28
 * @since 17
 */
@Controller
@RequestMapping("/r")
public class HelloController {

    @GetMapping("r1")
    // 不加@ResponBody   [\/WEB-INF\/templates\/r1.jsp] 未找到
    public String r1() {
        return "r1";
    }

    @GetMapping("r2")
    @ResponseBody // 直接返回数据到页面上，不需要.jsp去承载内容
    public String r2() {
        return "r1正文";
    }

    @GetMapping("r3")
    @ResponseBody // 直接返回数据到页面上，不需要.jsp去承载内容 直接返回json字符串
    public Map<String,Object> r3(HttpServletRequest req) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", "122");
        map.put("name", "张三");
        map.put("addr", req.getRemoteAddr());
        return map;
    }

}
